/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.alsutton.jabber.block;

import com.alsutton.jabber.JabberDataBlock;

/**
 *
 * @author dailicious
 */
public class Register extends JabberDataBlock {
/**
   * Constructor. Builds the string ready for sending to the server.
   *
   * @param username The username to log in with
   * @param password The password to log in with
   * @param resource The resource name to use
   */

  public Register(String username, String password)
  {
    super( );

    setAttribute("id", "reg_id" );
    setAttribute("type", "set" );

    JabberDataBlock queryBlock = new JabberDataBlock( "query", null, null );
    queryBlock.setAttribute( "xmlns", "jabber:iq:register" );

    addChild(queryBlock);

    if( username != null )
    {
      JabberDataBlock usernameBlock = new JabberDataBlock("username", null, null );
      usernameBlock.addText( username );
      queryBlock.addChild( usernameBlock );
    }

    if( password != null )
    {
      JabberDataBlock passwordBlock = new JabberDataBlock("password", null, null );
      passwordBlock.addText( password );
      queryBlock.addChild( passwordBlock );
    }

   
  }

  /**
   * Method to return the tag name
   *
   * @return Always the string "iq".
   */
  public String getTagName()
  {
    return "iq";
  }
}
